import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:wanchong/api/know.dart';
import 'package:wanchong/bean/strategy_detail_entity.dart';
import 'package:wanchong/widget/loading.dart';
import 'package:share/share.dart';


class Webviews extends StatefulWidget {
  final int id;
  Webviews({Key key, this.id});

  @override
  _WebviewsState createState() => _WebviewsState();
}

class _WebviewsState extends State<Webviews> {
  StrategyDetailData _mData;
  bool loading = false;
  @override
  void initState() {
    super.initState();
    strategyDetail(widget.id.toString()).listen((StrategyDetailEntity data) {
      loading = true;
      if (data.code == 200) {
        _mData = data.data;
      }
      setState(() {});
    });
  }

  Widget build(BuildContext context) {
    return !loading
        ? Loading()
        : Scaffold(
            appBar: new AppBar(
              elevation: 0.0,
              centerTitle: true,
              leading: Container(
                  padding: EdgeInsets.only(right: 15.0),
                  color: Colors.transparent,
                  height: double.infinity,
                  child: GestureDetector(
                    onTap: () {
                      Navigator.pop(context);
                    },
                    child: Image.asset("assets/login/top_return_icon.png"),
                  )),
              actions: <Widget>[
                new IconButton(
                  icon: new Icon(Icons.more_horiz),
                  tooltip: 'Add Alarm',
                  onPressed: () {
                    Share.share('check out my website https://example.com');
                  },
                ),
              ],
            ),
            body: SingleChildScrollView(
              physics: BouncingScrollPhysics(),
              padding: EdgeInsets.only(right: 15.0, left: 15.0,bottom: 20.0),
              child: Column(
                children: <Widget>[
                  Html(
                    data: _mData.content,
                  ),
                  Container(
                    // margin: EdgeInsets.only(bottom: 10.0),
                    height: 50,
                    child: Row(
                      children: <Widget>[
                        Container(
                          child: Text(
                            _mData.read.toString() + "  阅读量",
                            style: new TextStyle(
                                fontSize: 12.0, color: Color(0xFFB4BEC6)),
                          ),
                        ),
                        Expanded(
                          child: Container(
                            height: 50.0,
                          ),
                        ),
                        Container(
                          child: Row(
                            children: <Widget>[
                              Container(
                                width: 17.0,
                                height: 14.0,
                                child: Image.asset(
                                  'assets/user/zhishi_zantong_icon_a@2x.png',
                                  fit: BoxFit.cover,
                                ),
                              ),
                              Container(
                                margin: EdgeInsets.only(left: 5.0),
                                child: Text(
                                  _mData.agree.toString(),
                                  style: new TextStyle(
                                      fontSize: 12.0, color: Color(0xFFB4BEC6)),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  )
                ],
              ),
            ),
          );
  }
}
